<template>
  <el-container style="height: 100%">
    <el-aside width="205px" >
      <el-menu text-color="#bfcbd9" active-text-color="#ffd04b" background-color="#304156" class="sidebar-container" style="text-align: left">
        <el-sub-menu :index="item.name" v-for="item in menuList" :key="item.id">
          <template #title>
            <el-icon><svg-icon :icon="item.meta.icon"/></el-icon>
            {{item.meta.title}}
          </template>
          <el-menu-item :index="child.name" v-for="child in item.children" :key="item.id" style="padding-left: 40px" @click="selectMenu(item.path, child.path)">
            <template #title>
              <el-icon><svg-icon :icon="child.meta.icon"/></el-icon>
              {{child.meta.title}}
            </template>
          </el-menu-item>
        </el-sub-menu>
      </el-menu>
    </el-aside>
  <el-container>
    <el-header style="text-align: right">
      <el-dropdown :hide-on-click="false">
       <span class="el-dropdown-link">
        个人中心<svg-icon  icon="system"  />
       </span>
        <template #dropdown>
        <el-dropdown-menu >
          <el-dropdown-item>个人信息</el-dropdown-item>
          <el-dropdown-item @click.prevent.native="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
        </template >
      </el-dropdown>
<!--      <div style="height: 100%">
        <el-button link type="primary" @click.prevent.native="logout">退出登录</el-button>
      </div>-->
    </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
  </el-container>

  </el-container >
</template>

<script>
import {request} from "@/utils/request.js"

export default {
  name: "home",
  created() {
    this.getMenus()
  },
  methods: {
    getMenus() {
        request.get('api/menus/build').then(res => {
        this.menuList = res
      })
    },
    logout() {
      this.$store.dispatch('LogOut').then(() =>{
        this.$router.replace('/login')
      })
    },
    selectMenu(item, child) {
      this.$router.replace(item + '/' + child).catch(err=>err)
    }

  },
  data() {

    return {
      menuList:[]
    }
  }
}
</script>

<style scoped>
.sidebar-container{
background-color: #2d3a4b;
  color: #42b983;
height: 100%;
}
</style>
